﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:NJL_CS_AD_SPACE
	/// </summary>
	public partial class NJL_CS_AD_SPACE:INJL_CS_AD_SPACE
	{
		public NJL_CS_AD_SPACE()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from NJL_CS_AD_SPACE");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_CS_AD_SPACE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into NJL_CS_AD_SPACE(");
			strSql.Append("ID,AD_SPACE_NAME,AD_SPACE_WIDTH,AD_SPACE_HEIGHT,AD_SPACE_TYPE,AD_SPACE_STATE)");
			strSql.Append(" values (");
			strSql.Append("@ID,@AD_SPACE_NAME,@AD_SPACE_WIDTH,@AD_SPACE_HEIGHT,@AD_SPACE_TYPE,@AD_SPACE_STATE)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20),
					new SqlParameter("@AD_SPACE_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@AD_SPACE_WIDTH", SqlDbType.Int,4),
					new SqlParameter("@AD_SPACE_HEIGHT", SqlDbType.Int,4),
					new SqlParameter("@AD_SPACE_TYPE", SqlDbType.VarChar,20),
					new SqlParameter("@AD_SPACE_STATE", SqlDbType.VarChar,20)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.AD_SPACE_NAME;
			parameters[2].Value = model.AD_SPACE_WIDTH;
			parameters[3].Value = model.AD_SPACE_HEIGHT;
			parameters[4].Value = model.AD_SPACE_TYPE;
			parameters[5].Value = model.AD_SPACE_STATE;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_CS_AD_SPACE model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update NJL_CS_AD_SPACE set ");
			strSql.Append("AD_SPACE_NAME=@AD_SPACE_NAME,");
			strSql.Append("AD_SPACE_WIDTH=@AD_SPACE_WIDTH,");
			strSql.Append("AD_SPACE_HEIGHT=@AD_SPACE_HEIGHT,");
			strSql.Append("AD_SPACE_TYPE=@AD_SPACE_TYPE,");
			strSql.Append("AD_SPACE_STATE=@AD_SPACE_STATE");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@AD_SPACE_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@AD_SPACE_WIDTH", SqlDbType.Int,4),
					new SqlParameter("@AD_SPACE_HEIGHT", SqlDbType.Int,4),
					new SqlParameter("@AD_SPACE_TYPE", SqlDbType.VarChar,20),
					new SqlParameter("@AD_SPACE_STATE", SqlDbType.VarChar,20),
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = model.AD_SPACE_NAME;
			parameters[1].Value = model.AD_SPACE_WIDTH;
			parameters[2].Value = model.AD_SPACE_HEIGHT;
			parameters[3].Value = model.AD_SPACE_TYPE;
			parameters[4].Value = model.AD_SPACE_STATE;
			parameters[5].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_CS_AD_SPACE ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_CS_AD_SPACE ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_CS_AD_SPACE GetModel(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,AD_SPACE_NAME,AD_SPACE_WIDTH,AD_SPACE_HEIGHT,AD_SPACE_TYPE,AD_SPACE_STATE from NJL_CS_AD_SPACE ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			NJL.Model.NJL_CS_AD_SPACE model=new NJL.Model.NJL_CS_AD_SPACE();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AD_SPACE_NAME"]!=null && ds.Tables[0].Rows[0]["AD_SPACE_NAME"].ToString()!="")
				{
					model.AD_SPACE_NAME=ds.Tables[0].Rows[0]["AD_SPACE_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AD_SPACE_WIDTH"]!=null && ds.Tables[0].Rows[0]["AD_SPACE_WIDTH"].ToString()!="")
				{
					model.AD_SPACE_WIDTH=int.Parse(ds.Tables[0].Rows[0]["AD_SPACE_WIDTH"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AD_SPACE_HEIGHT"]!=null && ds.Tables[0].Rows[0]["AD_SPACE_HEIGHT"].ToString()!="")
				{
					model.AD_SPACE_HEIGHT=int.Parse(ds.Tables[0].Rows[0]["AD_SPACE_HEIGHT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AD_SPACE_TYPE"]!=null && ds.Tables[0].Rows[0]["AD_SPACE_TYPE"].ToString()!="")
				{
					model.AD_SPACE_TYPE=ds.Tables[0].Rows[0]["AD_SPACE_TYPE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AD_SPACE_STATE"]!=null && ds.Tables[0].Rows[0]["AD_SPACE_STATE"].ToString()!="")
				{
					model.AD_SPACE_STATE=ds.Tables[0].Rows[0]["AD_SPACE_STATE"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,AD_SPACE_NAME,AD_SPACE_WIDTH,AD_SPACE_HEIGHT,AD_SPACE_TYPE,AD_SPACE_STATE ");
			strSql.Append(" FROM NJL_CS_AD_SPACE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            strSql.Append(" order by ID asc");
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,AD_SPACE_NAME,AD_SPACE_WIDTH,AD_SPACE_HEIGHT,AD_SPACE_TYPE,AD_SPACE_STATE ");
			strSql.Append(" FROM NJL_CS_AD_SPACE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "NJL_CS_AD_SPACE";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

